<!--
 * @Author: Sam
 * @Date: 2020-11-10 15:35:38
 * @LastEditTime: 2021-05-24 16:03:57
 * @LastEditors: Sam
 * @Description: 
 * @FilePath: \resourcesf:\thework\ygboost-eui\src\components\app\edit\setting\channel\channelPriceTrial.vue
 * @可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <div class="padding">
    <el-card>
      <div slot="header" class="clearfix text-left">
        <span class="title-icon">运费试算</span>
      </div>

      <el-form :model="form" ref="priceTrialForm" :rules="rules" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item
              label="起运地："
              label-width="120px"
              prop="channelLoadingPortId"
            >
              <el-select
                size="mini"
                v-model="form.channelLoadingPortId"
                placeholder="请选择起运地"
              >
                <el-option
                  v-for="(item, value) in loadPortAddress"
                  :key="value"
                  :label="item"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="目的国：" label-width="120px" prop="countryId">
              <el-select
                size="mini"
                v-model="form.countryId"
                filterable
                placeholder="请选择目的国"
              >
                <el-option
                  v-for="(item, value) in countrys"
                  :key="value"
                  :label="item"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户：" label-width="120px" prop="customerId">
              <el-select
                size="mini"
                v-model="form.customerId"
                placeholder="请选择客户"
              >
                <el-option
                  v-for="(item, value) in loadPortAddress"
                  :key="value"
                  :label="item"
                  :value="value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="重量：" label-width="120px" prop="name">
              <el-input size="mini" v-model="form.weight"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="体积：" label-width="120px" prop="name">
              <el-input size="mini" v-model="form.volumn"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="渠道类型：" label-width="120px" prop="status">
              <el-select
                size="mini"
                v-model="form.channelType"
                placeholder="请选择渠道类型"
              >
                <el-option
                  v-for="item in channelTypeList"
                  :key="item.value"
                  :label="item.type"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item
          label="渠道能力："
          label-width="120px"
          prop="channelAbility1"
        >
          <el-checkbox-group size="mini" v-model="form.channelAbility1">
            <el-checkbox
              v-for="item in channelAbilitys"
              :key="item.id"
              :label="`${item.id}`"
              name="channelAbility"
            >
              {{ item.category }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item
          label="特殊产品："
          label-width="120px"
          prop="specialProduct1"
        >
          <el-checkbox-group size="mini" v-model="form.specialProduct1">
            <el-checkbox
              v-for="item in specialProducts"
              :key="item.id"
              :label="`${item.id}`"
              name="specialProduct"
            >
              {{ item.category }}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="其他：" label-width="120px" prop="other1">
          <el-checkbox-group size="mini" v-model="form.other1">
            <el-checkbox
              v-for="item in others"
              :key="item.id"
              :label="`${item.id}`"
              name="other"
              >{{ item.category }}</el-checkbox
            >
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card class="margin-top" v-if="tableInfo">
      <el-table
        class="table-box margin-top"
        :border="true"
        :data="tableInfo"
        style="width: 100%"
        size="mini"
      >
        <!-- 遍历col -->
        <el-table-column
          v-for="column in tableColumns"
          :key="column.prop"
          :prop="column.prop"
          :label="column.label"
        >
          <div slot-scope="scope">
            <template v-if="scope.column.property === 'customerChannel'">
              {{ scope.row[scope.column.property].name }}
            </template>
            <template v-else>
              {{ scope.row[scope.column.property] }}
            </template>
          </div>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { m } from "@/store/yg/common/local";
import { ajax } from "@/store/yg/common/utils";
export default {
  data() {
    return {
      channelAbilitys: [],
      channelTypeList: [],
      others: [],
      specialProducts: [],
      volumeWightRules: [],
      loadPortAddress: [],
      countrys: [],
      countryStates: [],
      tableInfo: [],
      tableColumns: [
        { prop: "customerChannel", label: "客户渠道" },
        { prop: "provinceId", label: "国内分区" },
        { prop: "finalWeight", label: "计费量" },
        { prop: "unitFreightCost", label: "运费单价" },
        { prop: "feightMoney", label: "运费总额" }
      ],
      form: {
        channelLoadingPortId: "",
        countryId: "",
        customerId: "",
        weight: "",
        volumn: "",
        bulkfactorRule: "",
        channelAbility1: [],
        specialProduct1: [],
        other1: [],
        channelAbility: [],
        specialProduct: [],
        other: []
      },
      rules: {
        customerId: [
          { required: true, message: "请选择客户", trigger: "change" }
        ],
        channelType: [
          { required: true, message: "请选择渠道类型", trigger: "change" }
        ],
        status: [{ required: true, message: "请选择状态", trigger: "change" }],
        name: [{ required: true, message: "请填写渠道名称", trigger: "blur" }],
        code: [{ required: true, message: "请选择渠道代码", trigger: "blur" }],
        bulkfactorRule: [
          { required: true, message: "请选择体积重规则", trigger: "change" }
        ],
        channelAbility1: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个",
            trigger: "change"
          }
        ],
        specialProduct1: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个",
            trigger: "change"
          }
        ],
        other1: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个",
            trigger: "change"
          }
        ]
      }
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      const data = await ajax("queryChannelPriceTrial", {
        channelLoadingPortId: "11",
        countryId: "4",
        weight: "30",
        volumn: "2",
        channelAbility: "3,12",
        other: "31,29,38",
        type: 0
      });
      console.log(
        "%cdata: ",
        "color: MidnightBlue; background: Aquamarine;",
        data
      );

      this.tableInfo = data;

      let initCustomerChannelData = localStorage.getItem(
        "initCustomerChannelData"
      );
      if (initCustomerChannelData && initCustomerChannelData !== "null") {
        initCustomerChannelData = JSON.parse(initCustomerChannelData);
      } else {
        initCustomerChannelData = await ajax("initCustomerChannelData", {});

        localStorage.removeItem("initCustomerChannelData");
        localStorage.setItem(
          "initCustomerChannelData",
          JSON.stringify(initCustomerChannelData)
        );
      }
      this.channelAbilitys = initCustomerChannelData.channelAbilitys;
      this.channelTypeList = initCustomerChannelData.channelTypeList;
      this.others = initCustomerChannelData.others;
      this.specialProducts = initCustomerChannelData.specialProducts;
      this.volumeWightRules = initCustomerChannelData.volumeWightRules;
      this.loadPortAddress = initCustomerChannelData.loadPortAddress;
      this.countrys = initCustomerChannelData.countrys;
      this.countryStates = initCustomerChannelData.countryStates;
      // this.countryStates = initCustomerChannelData.countryStates;
    },
    m(k) {
      return m(k);
    },
    callbefore() {
      // this.$store.state.edit.row = this.form;
      console.log("submit", this.$store.state.edit.row);
    },
    callvalidate() {
      // this.$refs.basisForm.validate(valid => {
      //   if (valid) {
      //     console.log("submit");
      //   } else {
      //     console.log("error submit!!");
      //     return false;
      //   }
      // });
      // return true;
    }
  }
};
</script>

<style></style>
